package cn.kgc.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/23
 * @Description:
 */
@RestController
@RequestMapping("user")
public class UserController {

    @RequestMapping("m1")
    @HystrixCommand(fallbackMethod = "fallbackMethodMethod1")
    public Map<String,Object> method1(Integer id){
        if (id<0) {
            throw  new RuntimeException("参数异常");
        }

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "ok");
        map.put("data", id);
        return map;
    }

    //  参数类别中的数据类型，要保持和method1一致
    public Map<String,Object> fallbackMethodMethod1(Integer id){
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", "参数异常");
        map.put("data", id);
        return map;
    }


}
